package ihm;

import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.util.Properties;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

import outil.PropertyLoader;

/**
 * Extension de JPanel redessinant une image de fond.
 * 
 * @author follignequ
 * 
 */
public class GridPanel extends JPanel {
	private static final long serialVersionUID = 1L;
	Image img;

	public GridPanel() {

	}

	public GridPanel(String path, String image) {
		setImg(path, image);

	}

	@Override
	public void paintComponent(Graphics graph) {
		graph.drawImage(img, 0, 0, getWidth(), getHeight(), this);
	}

	public Image getImg() {
		return img;
	}

	public void setImg(String path, String img) {

		if (img == null) {
			this.img = null;
			return;
		}

		try {
			Properties prop = PropertyLoader
					.load("res/properties/cgi.properties");
			this.img = ImageIO.read(new File(prop.getProperty(path) + img));
		} catch (Exception ex) {
			System.out.println("Image introuvable");
		}
		;
	}

}
